﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using XRM.Security.WebUI.Models.InfoSystem;
using XRM.Security.WebUI.Models.SystemUser;

namespace XRM.Security.WebUI.Models.UserRegister
{
    public class UserInfoSystemModel : BaseViewModel
    {
        public UserInfoSystemModel()
        {
        }

        public UserInfoSystemModel( DataAccess.Models.UserInfoSystem dbEntity )
        {
            Id = dbEntity.UserInfoSystemId;
            UserRegisterId = dbEntity.UserRegisterId;
            InfoSystemId = dbEntity.InfoSystemId;

            InfoSystem = new InfoSystemModel( dbEntity.InfoSystem );

            GrantDate = dbEntity.GrantDate;
            GrantSystemUser = new SystemUserModel( dbEntity.GrantSystemUser );
            RevokeDate = dbEntity.RevokeDate;
            RevokeSystemUser = new SystemUserModel( dbEntity.RevokeSystemUser );
            RevokeReason = dbEntity.RevokeReason;
        }

        public void GetGrantUser( DataAccess.Models.SystemUser user )
        {
            GrantSystemUser = new SystemUserModel( user );
        }

        public void GetRevokeUser( DataAccess.Models.SystemUser user )
        {
            RevokeSystemUser = new SystemUserModel( user );
        }

        public void GetInfoSystem( DataAccess.Models.InfoSystem user )
        {
            InfoSystem = new InfoSystemModel( user );
        }

        public int UserRegisterId { get; set; }
        public int InfoSystemId { get; set; }

        public InfoSystemModel InfoSystem { get; set; }

        public DateTime GrantDate { get; set; }
        public SystemUserModel GrantSystemUser { get; set; }

        public DateTime? RevokeDate { get; set; }
        public SystemUserModel RevokeSystemUser { get; set; }
        public string RevokeReason { get; set; }
    }

    public class RevokeInfoSystemModel
    {
        public int Id { get; set; }
        [Display( Name = "Дата запрета" )]
        public DateTime RevokeDate { get; set; }

        [AllowHtml]
        [Display( Name = "Комментарий" )]
        [Required( ErrorMessage = "Поле 'Комментарий' обязательное" )]
        public string RevokeReason { get; set; }
    }
}